home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / TestMatrix / ge_r < prev    next >
Encoding:
Text File  |  1994-12-20  |  1.3 KB  |  55 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Gaussian elimination without pivoting.
  4.  
  5. // Syntax:      GL = ge ( A )
  6.  
  7. // Description:
  8.  
  9. //      ge computes the factorization A = L*U, where L is unit lower
  10. //      triangular and U is upper triangular.  RHO is the growth
  11. //      factor. 
  12.  
  13. //      The return value, GL, is a list containing elements:
  14.  
  15. //              L   Lower unit triangular matrix.
  16. //              U   Upper triangular matrix.
  17. //            RHO   Growth factor.
  18.  
  19. //    This file is a translation of ge.m from version 2.0 of
  20. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  21. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  22.  
  23. //-------------------------------------------------------------------//
  24.  
  25. ge = function ( A )
  26. {
  27.   local (A)
  28.  
  29.   n = A.nc;
  30.   
  31.   rho = 0;
  32.   maxA = norm(A[;], "i");
  33.  
  34.   for (k in 1:n-1)
  35.   {
  36.     if (A[k;k] == 0)
  37.     {
  38.       error("Elimination breaks down with zero pivot.  Quitting...");
  39.     }
  40.  
  41.     A[k+1:n;k] = A[k+1:n;k]/A[k;k];          // Multipliers.
  42.  
  43.     // Elimination
  44.     i = k+1:n;
  45.     A[i;i] = A[i;i] - A[i;k] * A[k;i];
  46.     rho = max( rho, max(max(abs(A[i;i]))) );
  47.   }
  48.  
  49.   L = tril(A,-1) + eye(n,n);
  50.   U = triu(A);
  51.   rho = rho/maxA;
  52.  
  53.   return << L = L ; U = U; rho = rho >>;
  54. };
  55.